#include "lua.h"
#include "lauxlib.h"
#include "lualib.h"
#include "luajit.h"

#include <stdlib.h>
#include <stdio.h>
#include "tl/inflate.h"
#include "tl/png.h"
#include "tl/vector.h"
#include "tl/ieee.h"

static void openlib(lua_State* L, char const* name, lua_CFunction func)
{
	lua_pushcfunction(L, func);
	lua_pushstring(L, name);
	lua_call(L, 1, 0);
}

void report_error(lua_State* L)
{
	printf("Error: %s", lua_tostring(L, -1));
	lua_pop(L, 1);
	abort();
}

void checked_dofile(lua_State* L, char const* file)
{
	if(luaL_dofile(L, file))
	{
		report_error(L);
	}
}

int main(int argc, char* argv[])
{
#if 0
	test_inflate();
#elif 0
	test_png();
#elif 1
	int i;
	lua_State* L;
	
	gvl_init_ieee();

	L = luaL_newstate();

	luaL_openlibs(L);

	luaL_loadfile(L, "launch.lua");

	lua_createtable(L, argc, 0);
	for(i = 0; i < argc; ++i)
	{
		lua_pushstring(L, argv[i]);
		lua_rawseti(L, -2, i + 1);
	}
	
	if(lua_pcall(L, 1, LUA_MULTRET, 0))
		report_error(L);

	lua_close(L);
#endif
}

/*
	* General support
		* inflate library (C/++C)

	* 2D rastering/graphics
		* OpenGL window/rendering/input (C/++C)
		* Image manipulation
		* PNG loading (C/++C)

	* FreeType2 / other freetype support (C)

	* CMTP network support (C/++C)

	* Box2D (port) support (++C?)

	* Portaudio/mixer (C/++C)

	* Filesystem
*/